﻿using System;
using System.Data;
using System.Web.UI;
using MyWeb.Business;
using MyWeb.Data;

namespace MyWeb.TrangChinh.UC
{
    public partial class ucRegister : UserControl
    {
        private readonly UserService _userService = new UserService();
        private readonly DistributionService _distributionService = new DistributionService();
        private readonly StatisticsService _statisticsService = new StatisticsService();

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
          
            var user = new UserInfo
                           {
                               Username = txtUserName.Text,
                               Password = txtPassWord.Text.Trim(),
                               Rule = 0,
                               Email = txtEmail.Text,
                               CreateDate = DateTime.Now.ToString("yyyy-MM-dd"),
                               Status = true
                           };
            _userService.User_Insert(user);
            var statistics = new StatisticsInfo
                                 {
                                     User_Id = _userService.User_GetId(),
                                     ViewNumber=0
                                 };
            DataTable dtDistribution = _distributionService.Distribution_GetByAll();
            for (int i = 0; i < dtDistribution.Rows.Count; i++)
            {
                statistics.Distribution_Id = Int32.Parse(dtDistribution.Rows[i]["Id"].ToString());
                _statisticsService.Statistic_Insert(statistics);
            }
            multiview.ActiveViewIndex = 1;
        }
    }
}